import {
    ActionContext
} from 'vuex';

import * as types from './../types/user';
import * as ajax from './../../common/http';

export default {
    //登录
    [types.onLogin](
        context: ActionContext<any, any>,
        token: string
    ) {
        return (
            ajax.post(`/accesstoken`, {
                accesstoken: token
            }).then(res => {
                context.commit(
                    types.onLogin,{
                        ...res,
                        token:token
                    });
                return res;
            })
        )
    },
    //获取用信息
    [types.getUserProfile](
        context: ActionContext<any, any>,
        loginName: string
    ) {
        return (
            ajax.get(`/user/${loginName}`).
            then(res => {
                context.commit(
                    types.getUserProfile,
                    res
                );
                return res;
            })
        )
    }
}